﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media.Imaging;
using System.Windows.Media;
using OrderManager.Orders;

namespace OrderManager.ViewModels
{
    class OrderViewModel : DependencyObject
    {
        public static readonly DependencyProperty FlagProperty = DependencyProperty.Register("Flag", typeof(BitmapSource), typeof(OrderViewModel));
        public static readonly DependencyProperty BackgroundProperty = DependencyProperty.Register("Background", typeof(Brush), typeof(OrderViewModel));
        public static readonly DependencyProperty OrderProperty = DependencyProperty.Register("Order", typeof(Orders.Order), typeof(OrderViewModel));


        public static readonly BitmapSource RED = new BitmapImage(new Uri("/Images/Red.jpg", UriKind.Relative));
        public static readonly BitmapSource GREEN = new BitmapImage(new Uri("/Images/Green.jpg", UriKind.Relative));
        public static readonly BitmapSource YELLOW = new BitmapImage(new Uri("/Images/Yellow.jpg", UriKind.Relative));
        public static readonly BitmapSource BLUE = new BitmapImage(new Uri("/Images/Blue.jpg", UriKind.Relative));
        public static readonly BitmapSource PINK = new BitmapImage(new Uri("/Images/Pink.jpg", UriKind.Relative));
        public static readonly BitmapSource UN_LABLE = new BitmapImage(new Uri("/Images/None.jpg", UriKind.Relative));

        public string Item
        {
            get
            {
                if (this.Order == null)
                {
                    return "";
                }

                return this.Order.FirstItem.Name + " " + this.Order.FirstItem.Color + " " + this.Order.FirstItem.Size + " " + this.Order.Money + string.Format("({0})件", this.Order.FirstItem.Count);
            }
        }

        public Visibility RowDetailVisibility { get { return this.Order.AllItems.Count > 1 ? Visibility.Visible : Visibility.Collapsed; } }


        public BitmapSource Flag { get { return (BitmapSource)this.GetValue(FlagProperty); } set { this.SetValue(FlagProperty, value); } }

        public string Expander { get { return this.Order.AllItems.Count > 1 ? "多" : ""; } }

        public Brush Background { get { return (Brush)this.GetValue(BackgroundProperty); } set { this.SetValue(BackgroundProperty, value); } }

        public Order Order { get { return (Order)this.GetValue(OrderProperty); } set { this.SetValue(OrderProperty, value); } }

        public static BitmapSource Convert(OrderFlag flag)
        {
            if (flag == OrderFlag.UN_LABEL)
            {
                return UN_LABLE;
            }

            if (flag == OrderFlag.BLUE)
            {
                return BLUE;
            }

            if (flag == OrderFlag.GREEN)
            {
                return GREEN;
            }

            if (flag == OrderFlag.PINK)
            {
                return PINK;
            }

            if (flag == OrderFlag.RED)
            {
                return RED;
            }

            if (flag == OrderFlag.YELLOW)
            {
                return YELLOW;
            }

            throw new ArgumentException(flag.ToString());
        }

    }
}
